package org.icop.frame.select;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.icop.model.ValuedCorrespondence;
import org.icop.utils.MathUtils;
import org.jbpt.graph.abs.IEdge;
import org.jbpt.graph.abs.IGraph;
import org.jbpt.hypergraph.abs.IVertex;

public abstract class AbstractSelector<G extends IGraph<E,V>, E extends IEdge<V>, V extends IVertex> implements Selector<G, E, V> {

	protected boolean overlaps(Set<V> s1, Set<V> s2){
		Set<V> s1Copy = new HashSet<>(s1);
		s1Copy.retainAll(s2);
		return !s1Copy.isEmpty();
	}

	protected double getMaxMatchSim(Collection<ValuedCorrespondence<V>> matches) {
		double maxSim = 0;
		for (ValuedCorrespondence<V> m : matches) {
			if (maxSim < MathUtils.r(m.getConfidenceValue())) {
				maxSim = m.getConfidenceValue();
			}
		}
		return maxSim;
	}

	protected ValuedCorrespondence<V> getMaxSimMatch(Collection<ValuedCorrespondence<V>> matches) {
		ValuedCorrespondence<V> result = null;
		double maxSim = 0;
		for (ValuedCorrespondence<V> m : matches) {
			if (maxSim < MathUtils.r(m.getConfidenceValue())) {
				maxSim = m.getConfidenceValue();
				result = m;
			}
		}
		return result;
	}
}
